# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter


class LiepinPipeline:

    def open_spider(self, spider):
        self.file = open("liepin.csv", mode="w", encoding="utf-8")

    def process_item(self, item, spider):
        job_name = item["job_name"]
        location = item["location"]
        job_salary = item["job_salary"]
        years = item["years"]
        education = item["education"]
        tag = item["tag"]
        company_name = item["company_name"]
        hangye = item["hangye"]
        rongzi = item["rongzi"]
        guimo = item["guimo"]
        recruiter_name = item["recruiter_name"]
        recruiter_title = item["recruiter_title"]

        self.file.write(
            "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s" % (
                job_name,
                location,
                job_salary,
                years,
                education,
                tag,
                company_name,
                hangye,
                rongzi,
                guimo,
                recruiter_name,
                recruiter_title
            )
        )

        self.file.write("\n")

        return item
